#include "MenuInterface.h"
#include "DataBaseInterface.h"
#include <QVariant>
#include <QMutex>

MenuInterface* MenuInterface::mInstance = nullptr;

MenuInterface::MenuInterface()
{
}

MenuInterface::~MenuInterface()
{

}

MenuInterface* MenuInterface::GetInstance()
{
	if (mInstance == nullptr)
	{
		static QMutex mutex;
		mutex.lock();
		if (mInstance == nullptr)
		{
			static MenuInterface myDataTab;
			mInstance = &myDataTab;
		}
		mutex.unlock();
	}

	return mInstance;
}

int MenuInterface::ReadAllMenu(const QString& strSql, QString& outBa)
{
	int nRet = 0;
	QString strSqlError;
	nRet = ExecSql(strSql, strSqlError);
	if (nRet != 0)
	{
//		QString strErr = getErrorInfoFromCode(nRet);
//		outBa = QStringLiteral("%1:%2").arg(strErr).arg(strSqlError);
		return nRet;
	}

	while (mQuery.next())
	{
		//QJsonObject jsonChild;
		////jsonChild.insert("code", QJsonValue::fromVariant(QVariant::fromValue(query.value(0).toInt())));
		//QString strText = QStringLiteral("%1").arg(query.value(1).toString());
		//jsonChild.insert("text", QJsonValue::fromVariant(QVariant::fromValue(strText)));
		//jsonArray << jsonChild;
		//nCount++;
	}

	//jsonAll.insert("count", QJsonValue::fromVariant(QVariant::fromValue(nCount)));
	//jsonAll.insert("data", jsonArray);
	//QJsonDocument jsonDom(jsonAll);
	//outStr = jsonDom.toJson(QJsonDocument::Compact);

	mQuery.prepare("commit;");
	mQuery.exec();
}